package com.macrosoftinc.feedreaderxtreme.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.macrosoftinc.feedreaderxtreme.R;
import com.macrosoftinc.feedreaderxtreme.bean.TorrentType;

public class TorrentTypesExpandableAdapter extends BaseExpandableListAdapter {
	ArrayList<TorrentType> groups;
	Context context;

	public TorrentTypesExpandableAdapter(Context c, ArrayList<TorrentType> groups) {
		this.groups = groups;
		this.context = c;
	}

	@Override
	public Object getChild(int groupPosition, int childPosition) {
		// TODO Auto-generated method stub
		return groups.get(groupPosition).getItems().get(childPosition);
	}

	@Override
	public long getChildId(int groupPosition, int childPosition) {
		// TODO Auto-generated method stub
		return childPosition;
	}

	@Override
	public View getChildView(final int groupPosition, final int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
		// if (convertView == null) {
		// LayoutInflater inflater = LayoutInflater.from(context);
		// convertView = inflater.inflate(R.layout.list_item_skills, parent, false);
		// }
		// TextView tvPlayerName = (TextView) convertView.findViewById(R.id.tvSkillTitle);
		// tvPlayerName.setText(groups.get(groupPosition).getItems().get(childPosition).getTorrentTypeChildName());
		// return convertView;

		if (convertView == null) {
			convertView = LayoutInflater.from(context).inflate(R.layout.left_menu_row, null);
		}
		ImageView icon = (ImageView) convertView.findViewById(R.id.row_icon);
		icon.setImageResource(groups.get(groupPosition).getItems().get(childPosition).getResID());
		TextView title = (TextView) convertView.findViewById(R.id.row_title);
		title.setText(groups.get(groupPosition).getItems().get(childPosition).getTorrentTypeChildName());
		
		convertView.setPadding(15, 0, 0, 0);
		return convertView;
	}

	@Override
	public int getChildrenCount(int groupPosition) {
		// TODO Auto-generated method stub
		return groups.get(groupPosition).getItems().size();
	}

	@Override
	public Object getGroup(int groupPosition) {
		// TODO Auto-generated method stub
		return groups.get(groupPosition);
	}

	@Override
	public int getGroupCount() {
		// TODO Auto-generated method stub
		return groups.size();
	}

	@Override
	public long getGroupId(int groupPosition) {
		// TODO Auto-generated method stub
		return groupPosition;
	}

	@Override
	public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
		// if (convertView == null) {
		// LayoutInflater inflater = LayoutInflater.from(context);
		// convertView = inflater.inflate(R.layout.row, parent, false);
		// }
		// TextView tvGroupName = (TextView) convertView.findViewById(R.id.tvSkillGroup);
		// tvGroupName.setText(groups.get(groupPosition).getTorrentTypeName());
		// // tvGroupName.setText("Group Row");
		// return convertView;

		if (convertView == null) {
			convertView = LayoutInflater.from(context).inflate(R.layout.left_menu_row, null);
		}
		ImageView icon = (ImageView) convertView.findViewById(R.id.row_icon);
		icon.setImageResource(groups.get(groupPosition).getIconRes());
		TextView title = (TextView) convertView.findViewById(R.id.row_title);
		title.setText(groups.get(groupPosition).getTorrentTypeName());
		return convertView;
	}

	@Override
	public boolean hasStableIds() {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean isChildSelectable(int groupPosition, int childPosition) {
		// TODO Auto-generated method stub
		return true;
	}

}
